package com.jl.easybuysys.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jl.easybuysys.mapper.EbProductCategoryMapper;
import com.jl.easybuysys.mapper.EbProductMapper;
import com.jl.easybuysys.model.EbProduct;
import com.jl.easybuysys.model.EbProductCategory;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EbProductCategoryService {
    @Autowired
    private EbProductCategoryMapper ebProductCategoryMapper;
    @Autowired
    private EbProductMapper ebProductMapper;
    /*根据分类id查询该分类的所有商品*/
    public Page<EbProduct> findProductByCate(int psize,int pageSize,int epcId){
        Page<EbProduct> page = new Page(psize,pageSize);
        return ebProductMapper.selectPage(page,new QueryWrapper<EbProduct>()
                .eq("epc_child_id",epcId));
    }
    /*查询所有大类和所有小类*/
    public Map<String, List<EbProductCategory>> selectBigAndSmallCate(){
        //TODO 1.查询大类
        List<EbProductCategory> bigCates = ebProductCategoryMapper.selectBigCate();
        //TODO 2.查询所有小类
        List<EbProductCategory> smallCates = ebProductCategoryMapper.selectSmallCate();
        //TODO 3.将大类集合和小类集合封装到map集合
        Map<String,List<EbProductCategory>> cateMap = new HashMap<>();
        cateMap.put("bigs",bigCates);
        cateMap.put("small",smallCates);
        return cateMap;
    }
}
